package java学习.实训.day05;

/**
 * **************
 * 项目名称: 蓝桥杯 <br/>
 * 文件名称:  <br/>
 * 文件描述: 这里添加您的类文件描述，说明当前文件要包含的功能。 <br/>
 * 文件创建：刘世锦 <br/>
 * 创建时间: 2022/6/13 <br/>
 *
 * @version v1.0 <br/>
 * @update [序号][日期YYYY-MM-DD][更改人姓名][变更描述]<br/>
 * *************
 */
public class day05 {
    public static void main(String[] args) {
        Graph circle = new Circle(3.5);
        System.out.println(circle.toString());
        Graph rectangle = new Rectangle(2,4);
        System.out.println(rectangle.toString());
        Graph square = new Square(3.5);
        System.out.println(square.toString());
    }
}

abstract class Graph {

    public abstract double perimeter();

    public abstract double area();

}
class Square extends  Graph{
    private double l;

    public Square() {
    }

    public Square(double l) {
        this.l = l;
    }

    public double getL() {
        return l;
    }

    public void setL(double l) {
        this.l = l;
    }

    @Override
    public double perimeter() {
        return l*4;
    }

    @Override
    public double area() {
        return l*l;
    }

    @Override
    public String toString() {
        return "Square{" +
                "l=" + l +
                " perimeter=" + perimeter( ) +
                " area=" + area( ) +
                '}';
    }
}
class Rectangle extends Graph{
    private double l;
    private double w;

    public double getL() {
        return l;
    }

    public void setL(double l) {
        this.l = l;
    }

    public double getW() {
        return w;
    }

    public void setW(double w) {
        this.w = w;
    }

    public Rectangle() {
    }

    public Rectangle(double l, double w) {
        this.l = l;
        this.w = w;
    }

    @Override
    public double perimeter() {
        return (l+w)*2;
    }

    @Override
    public double area() {
        return l*w;
    }

    @Override
    public String toString() {
        return "Rectangle{" +
                "l=" + l +
                ", w=" + w +
                " perimeter=" + perimeter( ) +
                " area=" + area( ) +
                '}';
    }
}
 class Circle extends Graph{
    private double x;
    private double y;
    private double r;
    public static final double PI = 3.1415926;

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

    public double getR() {
        return r;
    }

    public void setR(double r) {
        this.r = r;
    }

    /**
     *
     *
     * @return
     */
    @Override
    public double area( ){

        return PI*r*r;
    }

    /**
     *
     * @return
     */
    @Override
    public double  perimeter(){
        return 2*PI*r;
    }

    public  boolean IsIntersect( Circle c  ){
        double dis = Math.sqrt( x-c.x)*( x-c.x)+( y-c.y)*( y-c.y);
        double sum = r + c .r;

        return sum >= dis;
    }


    public Circle(double x, double y, double r) {
        this.x = x;
        this.y = y;
        this.r = r;
    }

    public Circle(double r) {
        this.r = r;
    }

    @Override
    public String toString() {
        return "Circle{" +
                " r=" + r +
                " perimeter=" + perimeter( ) +
                " area=" + area( ) +
                '}';
    }

}

